<template>
    <div>
        <input type="text" v-model="text"><br>
        <input type="text" v-model.number.trim="n">
        <button @click="submit">提交</button><br>
        <input type="text" v-model="a">+
        <input type="text" v-model.number.trim="b">=
        <input type="text" v-model="c">
        <button @click="add">加</button><br>
        <input type="text" v-model="a">-
        <input type="text" v-model.number.trim="b">=
        <input type="text" v-model="c">
        <button @click="minus">减</button><br>
        <input type="text" v-model="a">*
        <input type="text" v-model.number.trim="b">=
        <input type="text" v-model="c">
        <button @click="multi">乘</button><br>
        <input type="text" v-model="a">/
        <input type="text" v-model.number.trim="b">=
        <input type="text" v-model="c">
        <button @click="divide">除</button><br>
    </div>
</template>


<script>
import bigUtils from '@/utils/bignumber.js'
import {ROUND_MODE} from '@/utils/bignumber.js'
export default {
    data() {
        return {
            text: '',
            n: '',
            tranvale: '',
            a: '',
            b: '',
            c: ''
        }
    },
    mounted() {
        // bigUtils.initBigNumber(this.config)
    },
    methods: {
        submit() {
            try {
                this.tranvale = bigUtils.getBigNumber(this.text, this.n);
                console.log(bigUtils.getBigNumber(this.text, this.n));
            } catch (error) {
                console.log(error);
            }
        },
        add() {
            console.log(bigUtils);
            this.c = bigUtils.plus(this.a, this.b)
        },
        minus() {
            this.c = bigUtils.minus(this.a, this.b)
        },
        multi() {
            this.c = bigUtils.multiply(this.a, this.b)
        },
        divide() {
            this.c = bigUtils.divided(this.a, this.b, {
                DECIMAL_PLACES: 6,
                ROUNDING_MODE: ROUND_MODE.ROUND_HALF_UP
            })
        }
    },
    // watch: {
    //     text(value) {

    //     }
    // }
}
</script>